//
//  ItemDetailViewController.m
//  tradersOnMap
//
//  Created by bilmuh bilmuh on 11.05.2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ItemDetailViewController.h"


@implementation ItemDetailViewController

-(void)setup
{
	NSUserDefaults *def = [[NSUserDefaults alloc] init];
    NSData* xmlData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://sorubank.ege.edu.tr/~b05067683/tez/getItemDetail.php?itemID=%@",[def objectForKey:@"itemID"]]]];
    NSError* error;
    GDataXMLDocument* doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&error];
    NSArray *itemNodes = [doc nodesForXPath:@"//item" error:nil];
	
	for (GDataXMLNode *itemNode in itemNodes)
	{
		UIImage *image = [UIImage imageWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", ((GDataXMLElement*) [[itemNode nodesForXPath:@"imageURL" error:nil] objectAtIndex:0]).stringValue]]]];
		[imageView setImage:image];
		[priceText setText:((GDataXMLElement*) [[itemNode nodesForXPath:@"price" error:nil] objectAtIndex:0]).stringValue];
		[titleText setText:((GDataXMLElement*) [[itemNode nodesForXPath:@"itemTitle" error:nil] objectAtIndex:0]).stringValue];
		[descriptionText setText:((GDataXMLElement*) [[itemNode nodesForXPath:@"description" error:nil] objectAtIndex:0]).stringValue];
	}
}

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
	self = [super initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil];
	if (self) {
		[self setup];
	}
	return self;
}

-(void)awakeFromNib
{
	[self setup];
}

-(void) viewDidLoad{
	[self setup];
}

-(BOOL) textFieldShouldReturn:(UITextField *)textField
{
	[textField resignFirstResponder];
	return YES;
}

-(IBAction)updateButtonPressed
{
	/*NSString *title = titleText.text;
	NSString *description = descriptionText.text;
	NSString *price = priceText.text;
	NSUserDefaults *def = [[NSUserDefaults alloc] init];
	NSString *itemID = [def objectForKey:@"itemID"];
	[def release];*/
}

@end
